#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<unistd.h>
#define myerr(m)do{perror(m);exit(EXIT_FAILURE);}while(0)

int main()
{
    const char* fifo_path = "./myfifo";
    if(mkfifo(fifo_path,0666) == -1)
        myerr("mkfifo");
    int rfd = open(fifo_path,O_RDONLY);
    if(rfd < 0)
        myerr("open");
    printf("open fifo true\n");
    char carr[512];
    while(1)
    {
        carr[0] = 0;
        ssize_t rsz = read(rfd,carr,sizeof(carr)-1);
        if(rsz == 0)
        {
            printf("read nothing exit\n");
            exit(0);
        }
        else if(rsz > 0)
        {
            carr[rsz] = 0;
            printf("client say: %s\n",carr);
        }
        else{
            myerr("read");
        }

    }
    close(rfd);
    return 0;
}